package com.example.schoolguider.config;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author wjc
 * @date 2024/6/10 12:36
 */
@Component
public class RedisHeartbeat {

    private final StringRedisTemplate redisTemplate;

    public RedisHeartbeat(StringRedisTemplate redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    // 每30秒执行一次
    @Scheduled(fixedRate = 30000)
    public void sendPing() {
        redisTemplate.getConnectionFactory().getConnection().ping();
    }
}